<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2005/05/26 22:02:02 $)
// $RCSfile: rss_view.php,v $ : $Revision: 1.2 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

require_once ("./modules/downloads/functions_downloads.php");
require_once ("./modules/downloads/functions_clientdl.php");
require_once ("./includes/functions_users.php");
require_once ("./includes/functions_xml.php");
require_once ("./includes/functions_comments.php");
$template->loadLanguageSection("downloads", TEMPLATE_DB);
$xml = new XML;

if ($_SWIFT["settings"]["dl_enrss"] != 1)
{
	exit;
}

if (empty($_GET["downloadcategoryid"]))
{
	$_downloadcategoryid = 0;
} else {
	$_downloadcategoryid = intval($_GET["downloadcategoryid"]);
}

$_downloadcategory = $dbCore->queryFetch("SELECT * FROM `". TABLE_PREFIX ."downloadcategories` WHERE `downloadcategoryid` = '". intval($_GET["downloadcategoryid"]) ."';");
if (empty($_downloadcategory["downloadcategoryid"]) && $_downloadcategoryid != 0)
{
	// No such category
	echo $_SWIFT["language"]["invaliddlcat"];
	exit;
}

$downloaditemlist = array();
$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."downloaditems` AS downloaditems LEFT JOIN `". TABLE_PREFIX ."downloaddesc` AS downloaddesc ON (downloaditems.downloaditemid = downloaddesc.downloaditemid) WHERE downloaditems.downloadcategoryid = '". intval($_downloadcategoryid) ."';");
while ($dbCore->nextRecord())
{
	$downloaditemlist[$dbCore->Record["downloaditemid"]] = $dbCore->Record;
}

$xml->addParentTag("rss", array("version" => "2.0"));
	$xml->addParentTag("channel");
		$xml->addTag("title", sprintf($_SWIFT["language"]["rssdl"], iif(empty($_downloadcategory["title"]), $_SWIFT["language"]["dlparentcat"], $_downloadcategory["title"])));
		$xml->addTag("link", $_SWIFT["swiftpath"]."index.php?_m=downloads&_a=view&parentcategoryid=".intval($_downloadcategoryid));
		$xml->addTag("description", sprintf($_SWIFT["language"]["rssdldesc"], $_SWIFT["settings"]["general_companyname"]));
		$xml->addTag("language", $_SWIFT["adminlanguage"]);
		$xml->addTag("copyright", $_SWIFT["settings"]["general_companyname"]);

		foreach ($downloaditemlist as $key=>$val)
		{
			$xml->addParentTag("item");
				$xml->addTag("title", htmlspecialchars($val["title"]));
				$xml->addTag("link", iif($_SWIFT["settings"]["dl_rsslinkfile"]==1&&empty($val["itempassword"]),$_SWIFT["swiftpath"]."index.php?_m=downloads&_a=downloadfile&downloaditemid=". intval($val["downloaditemid"]), $_SWIFT["swiftpath"]."index.php?_m=downloads&_a=viewdownload&downloaditemid=". intval($val["downloaditemid"])));
				$xml->addTag("description", htmlspecialchars($val["description"]));
			$xml->endParentTag("item");
		}

	$xml->endParentTag("channel");
$xml->endParentTag("rss");

header("Content-Type: text/xml".SWIFT_CRLF);
echo $xml->returnXML();
?>